package site.shihuan.helpdesk.service.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.shihuan.helpdesk.common.model.RestResult;
import site.shihuan.helpdesk.common.model.RestResultUtils;
import site.shihuan.helpdesk.security.context.UserContext;
import site.shihuan.helpdesk.service.manager.CustomerManager;
import site.shihuan.helpdesk.service.model.po.SvcCustomerPO;

/**
 * 联系人API
 *
 * @author 周世焕
 * @Date 2021/4/25 11:07
 */
@RestController
@RequestMapping("/v1/service/customer")
public class CustomerController {

    @Autowired
    private CustomerManager customerManager;

    @GetMapping("list")
    public RestResult findCustomerList() {
        return RestResultUtils.success(customerManager.findCustomerList(UserContext.getTenantId(), UserContext.getUserId()));
    }

    @GetMapping
    public RestResult findById(@RequestParam String customerId) {
        return RestResultUtils.success(customerManager.findById(customerId));
    }

    @GetMapping("followList")
    public RestResult findCustomerFollowList() {
        return RestResultUtils.success(customerManager.findCustomerFollowList(UserContext.getTenantId(), UserContext.getUserId()));
    }

    @DeleteMapping
    public RestResult deleteCustomer(@RequestParam String customerId) {
        customerManager.deleteCustomer(UserContext.getTenantId(),customerId);
        return RestResultUtils.success();
    }

    @PostMapping
    public RestResult saveCustomer(@RequestBody SvcCustomerPO customerPO) {
        customerPO.setTenantId(UserContext.getTenantId());
        return RestResultUtils.success(customerManager.saveCustomer(customerPO));
    }

    @PostMapping("star")
    public RestResult starCustomer(@RequestParam String customerId) {
        customerManager.starCustomer(customerId,UserContext.getUserId(),UserContext.getTenantId());
        return RestResultUtils.success();
    }

    @DeleteMapping("star")
    public RestResult unStarCustomer(@RequestParam String customerId) {
        customerManager.unStarCustomer(customerId,UserContext.getUserId(),UserContext.getTenantId());
        return RestResultUtils.success();
    }
}
